home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra_2 / nadir11.zip / MTCE.N < prev    next >
Text File  |  1995-11-08  |  10KB  |  317 lines

  1. Define MtceSelFmt(key) {
  2.     if (suf = parm^mtce^suf) {
  3.         if (!StrMatch(suf, key)) {
  4.             return "";
  5.         }
  6.     }
  7.     return key;
  8. }
  9. Define MtceScrCreate()
  10. {
  11.     showVal = parm^mtce^showVal;
  12.     width = parm^mtce^width;
  13.     table = glob^mtce^table;
  14.     selHt = parm^mtce^selHt;
  15.     valHt = parm^mtce^valHt;
  16.  
  17.     if (selHt < 5)          selHt = 5;
  18.     else if (selHt > 16)    selHt = 16;
  19.  
  20.     if (valHt < 5)          valHt = 5;
  21.     else if (valHt > 16)    valHt = 16;
  22.  
  23.     if (width < 42)         width = 42;
  24.     else if (width > 78)    width = 78;
  25.  
  26.     title = "Table Maintenance - " . table;
  27.     if (match = parm^mtce^match)
  28.         title .= ", match " . match;
  29.  
  30.     scr = SdCreate(, -1, -1, 1 + selHt + (showVal ? valHt : 0), width, title);
  31.  
  32.     SdSelect(scr, "sel",  1, 0, 1, width - 2, selHt, ,
  33.                     table . "^" . match, 131,
  34.                     , 130, showVal ? 131 : "");
  35.  
  36.     row = selHt;
  37.     if (showVal) {
  38.         SdMultiLine(scr, "val", 0, row, 1, width - 2, valHt, , 2048, "Literal");
  39.         code = MtceSelCode(scr);
  40.         SdFieldSet(scr, "val", [table]^[parm^mtce^pre][code]);
  41.         row += valHt;
  42.     }
  43.  
  44.     btnLen = (width - 2) / 4;
  45.     col = 1;
  46.     SdButton(scr, "mod",   1, row, col, btnLen, "Modify",  "m", 122);
  47.     col += btnLen;
  48.     SdButton(scr, "add",   1, row, col, btnLen, "Add",     "a", 123);
  49.     col += btnLen;
  50.     SdButton(scr, "del",   1, row, col, btnLen, "Delete",  "d", 124);
  51.     col += btnLen;
  52.     SdButton(scr, "opt",   1, row, col, btnLen, "Options", "o", 120);
  53.     return scr;
  54. }
  55. Define MtceSelCode(scr)
  56. {
  57.     return SdFieldGet(scr, "sel");
  58. }
  59. Define MtceSelFieldSet(scr, code)
  60. {
  61.     SdFieldSet(scr, "sel", code);
  62.     if (parm^mtce^showVal)
  63.         SdFieldSet(scr, "val", [glob^mtce^table]^[parm^mtce^pre][code]);
  64. }
  65. Define MtceSelNext(code)
  66. {
  67.     if (nxt = next([glob^mtce^table]^[parm^mtce^pre][code]))
  68.         return nxt;
  69.     return prev([glob^mtce^table]^[parm^mtce^pre][code]);
  70. }
  71. Define Mtce(table)
  72. {
  73.     if (!table)
  74.         table = "univ";
  75.     glob^mtce^table = table;
  76.  
  77.     scr = MtceScrCreate();
  78.  
  79.  
  80.     while (action != 2 && action != 3) {
  81.         switch(action = SdEdit(scr)) {
  82.         case 120:                       // pressed options button
  83.             code = MtceSelCode(scr);
  84.             if (MtceOpt() == 1) {
  85.                 SdDestroy(scr);
  86.                 scr = MtceScrCreate();
  87.                 MtceSelFieldSet(scr, code);
  88.             }
  89.             break;
  90.  
  91.         case 130:                       // double click select box
  92.         case 122:                       // pressed modify button
  93.             if (MtceMod(code = MtceSelCode(scr)) == 1)
  94.                 MtceSelFieldSet(scr, code);
  95.             break;
  96.  
  97.         case 131:                       // moved to or selected in select box
  98.             code = MtceSelCode(scr);
  99.             SdFieldSet(scr, "val", [glob^mtce^table]^[parm^mtce^pre][code]);
  100.             break;
  101.  
  102.         case 123:                       // pressed add button
  103.             if (MtceAdd(&code) == 1)
  104.                 MtceSelFieldSet(scr, code);
  105.             break;
  106.  
  107.         case 124:                       // pressed delete button
  108.             code = MtceSelCode(scr);
  109.             if (MsgYesNo("", 
  110.                          "Delete ". code. ", are you sure ?") == 1) {
  111.                 nextCode = MtceSelNext(code);
  112.                 [glob^mtce^table]^[parm^mtce^pre][code] = "";
  113.                 MtceSelFieldSet(scr, nextCode);
  114.             }
  115.             break;
  116.         }
  117.     }
  118.     SdDestroy(scr);    
  119. }
  120. Define MtceOptWidthValn(scr, value, name) {
  121.     if (!value)             /* may be blank */
  122.         return "";
  123.     if (value < 42 || value > 78) {
  124.         MsgWait("", "Width must be between 42 and 78 inclusive");
  125.         return 1;
  126.     }
  127. }
  128. Define MtceOptSelHtValn(scr, value, name) {
  129.     if (!value)             /* may be blank */
  130.         return "";
  131.     if (value < 5 || value > 16) {
  132.         MsgWait("", "Select height must be between 5 and 16 inclusive");
  133.         return 1;
  134.     }
  135.     if (value + SdFieldGet(scr, "valht") > 20) {
  136.         MsgWait("", "Sum of select and value height must less than 21");
  137.         return 1;
  138.  
  139.     }
  140. }
  141. Define MtceOptValHtValn(scr, value, name) {
  142.     if (!value)             /* may be blank */
  143.         return "";
  144.     if (value < 5 || value > 16) {
  145.         MsgWait("", "Value height must be between 5 and 16 inclusive");
  146.         return 1;
  147.     }
  148.     if (value + SdFieldGet(scr, "selht") > 20) {
  149.         MsgWait("", "Sum of select and value height must less than 21");
  150.         return 1;
  151.  
  152.     }
  153. }
  154. Define MtceOpt()
  155. {
  156.     scr = SdCreate("", -2, -2, 10, 60, "Options");
  157.     SdPrompt(scr, 1,  1, "Match Pattern:");
  158.     SdString(scr, "mch",    1, 1, 16, 32, &parm^mtce^match, 128, "Caret");
  159.  
  160.     SdPrompt(scr, 2,  1, "Screen Width:");
  161.     SdInt   (scr, "wid",    1, 2, 16, 3, &parm^mtce^width, "MtceOptWidthValn");
  162.     SdPrompt(scr, 3,  1, "Select Height:");
  163.     SdInt   (scr, "selht",  1, 3, 16, 3, &parm^mtce^selHt, "MtceOptSelHtValn");
  164.     SdPrompt(scr, 4,  1, "Value Height:");
  165.     SdInt   (scr, "valht",  1, 4, 16, 3, &parm^mtce^valHt, "MtceOptValHtValn");
  166.  
  167.     SdCheck (scr, "c0",   1, 6, 1, 32, &parm^mtce^showVal, 
  168.                             "Show value with select", "s");
  169.     SdButton(scr, "ok",   1, 8, 15, 10, "OK", "", 1);
  170.     SdButton(scr, "can",  1, 8, 30, 10, "Cancel", "", 2);
  171.     if ((action = SdEdit(scr)) == 1) {
  172.         SdUpdate(scr);
  173.         StrPatternParts(parm^mtce^match, &parm^mtce^pre, &parm^mtce^suf);
  174.     }
  175.     SdDestroy(scr);    
  176.     return action;
  177. }
  178. Define MtceModScrCreate(title)
  179. {
  180.     scr = SdCreate(, -1, -1, 14, 72, title . " - " . glob^mtce^table . "^"
  181.                                            . parm^mtce^pre);
  182.  
  183.     SdPrompt(scr, 1,  1, "Name:");
  184.     SdString(scr, "code",  0,  1, 7, 64, , 128, "Caret");
  185.     SdPrompt(scr, 2,  1, "Value(literal):");
  186.     SdMultiLine(scr, "val", 1, 3, 1, 70, 8, "", 2048, "Caret, Literal");
  187.  
  188.     SdButton(scr, "ok",   1, 12, 21, 10, "OK", "", 1);
  189.     SdButton(scr, "can",  1, 12, 36, 10, "Cancel", "", 2);
  190.     return scr;
  191. }
  192. Define MtceMod(code)
  193. {
  194.     scr = MtceModScrCreate("Modify Symbol");
  195.     SdModeSet(scr, 0, "code");
  196.     SdFieldVar(scr, "code", code);
  197.     SdFieldVar(scr, "val", &[glob^mtce^table]^[parm^mtce^pre][code]);
  198.     if ((action = SdEdit(scr)) == 1) {
  199.         SdUpdate(scr);
  200.     }
  201.     SdDestroy(scr);    
  202.     return action;
  203. }
  204. Define MtceAdd(code)
  205. {
  206.     scr = MtceModScrCreate("Add Symbol");
  207.     SdModeSet(scr, 1, "code");
  208.     while ((action = SdEdit(scr)) == 1) {
  209.         code = SdFieldGet(scr, "code");
  210.         if (!code) {
  211.             MsgWait( , "Symbol Name must be specified");
  212.             continue;
  213.         }
  214.         if ([glob^mtce^table]^[parm^mtce^pre][code]) {
  215.             MsgWait( , "Symbol Name already exists");
  216.             continue;
  217.         }
  218.         SdFieldVarChg(scr, "val", &[glob^mtce^table]^[parm^mtce^pre][code]);
  219.         SdUpdate(scr);
  220.         break;
  221.     }
  222.     SdDestroy(scr);    
  223.     return action;
  224. }
  225. If(0)
  226. 0----+----1----+----2----+----3----+----4----+----5---
  227.                                                         0
  228.   [ ] univ     [ ] mdat     [ ] parm     [ ] data       1
  229.                                                         2
  230.   Data Filename: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    3
  231.                                                         4
  232.              [   OK   ]       [ Cancel ]                5
  233.                                                         6
  234.  
  235. Endif
  236. Define MtceTableSelect(title, table, tableName)
  237. {
  238.     glob^table^letter^["univ"] = "u";
  239.     glob^table^letter^["mdat"] = "m";
  240.     glob^table^letter^["parm"] = "p";
  241.     glob^table^letter^["data"] = "d";
  242.  
  243.     glob^table^name^["u"] = "univ";
  244.     glob^table^name^["m"] = "mdat";
  245.     glob^table^name^["p"] = "parm";
  246.     glob^table^name^["d"] = "data";
  247.  
  248.     if (!(tableLetter = glob^table^letter^[table]))
  249.         tableLetter = "u";
  250.  
  251.     scr = SdCreate(, -1, -1, 7, 54, title);
  252.     SdRadio (scr, "rad", 1, 1, 2, 12, &tableLetter, "Univ", "u", 131);
  253.     SdRadio (scr, "", 1, 1, 15, 12, &tableLetter, "Mdat", "m", 131);
  254.     SdRadio (scr, "", 1, 1, 28, 12, &tableLetter, "Parm", "p", 131);
  255.     SdRadio (scr, "", 1, 1, 41, 12, &tableLetter, "Data", "d", 132);
  256.     SdPrompt(scr, 3, 2, "Data Filename:");
  257.     SdString(scr, "inf",  tableLetter == "d",  3, 17, 33, &tableName, 64);
  258.  
  259.     SdButton(scr, "", 1,    5, 13, 10, "OK",     "", 1);
  260.     SdButton(scr, "", 1,    5, 30, 10, "Cancel", "", 2);
  261.  
  262.     do {
  263.         cmd = SdEdit(scr, cursor);
  264.  
  265.         switch (cmd) {
  266.         case 1:
  267.             SdUpdate(scr);
  268.             if (!tableLetter) {
  269.                 MsgWait(title, "Must choose source Symbol Table");
  270.                 cursor = "sym";
  271.                 continue;
  272.             }
  273.             else if (tableLetter == "d") {
  274.                 if (!tableName) {
  275.                     MsgWait(title, "For Data, must specify a Data Filename");
  276.                     cursor = "inf";
  277.                     continue;
  278.                 }
  279.                 if (SymOpen("data", tableName)) {
  280.                     MsgWait(title, "Could not open Data Filename");
  281.                     cursor = "inf";
  282.                     continue;
  283.                 }
  284.             }
  285.             table = glob^table^name^[tableLetter];
  286.  
  287.         case 2:
  288.         case 3:
  289.             end = "y";
  290.             break;
  291.  
  292.         case 131:
  293.             SdModeSet(scr, 0, "inf");
  294.             cursor = "rad";
  295.             continue;
  296.  
  297.         case 132:
  298.             SdModeSet(scr, 1, cursor = "inf");
  299.             continue;
  300.         }
  301.     } while (!end);
  302.  
  303.     SdDestroy(scr);
  304.     return cmd;
  305. }
  306. Define MtceSelect()
  307. {
  308.     while (MtceTableSelect("Select Table to Maintain", 
  309.                            &table, &tableName) == 1) {
  310.         if (table == "data")
  311.             doneData = "y";
  312.         Mtce(table);
  313.     }
  314.     if (doneData)
  315.         Signal("");                     // to restart system
  316. }
  317.